'use strict';

app.controller('viewRecordCtrl', function($element, $scope, $state, rest, user, $rootScope, ngDialog, uiLoad, $timeout, $window) {
    var data = angular.copy($scope.ngDialogData, {});
    var token = $window.localStorage.getItem("token");

    $scope.queryParams = {
        id: data.id,
    };
    $scope.$on('msg2', function(e, msg) {
        $scope.confirm({});
    });

    $scope.tableLoanDatas = {
        "sAjaxSource": "/tenancy-sys/admin/house/getHouseProcess",
        "dom": "tr",
        "aoColumns": [{
            "mDataProp": "StageStatus",
            "sTitle": "阶段",
            "sDefaultContent": "",
            "sClass": "center houseStatus1",
            "sWidth": "120px"
        }, {
            "mDataProp": "planRepaymentDate",
            "sTitle": "操作",
            "sDefaultContent": "",
            "sClass": "center operateStatus",
            "sWidth": "120px"
        }, {
            "mDataProp": "approverTime",
            "sTitle": "操作时间",
            "sDefaultContent": "",
            "sClass": "center"
        }, {
            "mDataProp": "approverUserName",
            "sTitle": "审核人",
            "sDefaultContent": "",
            "sClass": "center"
        }, {
            "mDataProp": "remark",
            "sTitle": "审核意见",
            "sDefaultContent": "",
            "sClass": "center"
        }, {
            "mDataProp": "houseProcessStatus",
            "sTitle": "目标状态",
            "sDefaultContent": "",
            "sClass": "center houseStatus"
        }],
        "fnRowCallback": function(nRow, aData, iDisplayIndex) {

            if (aData.stageStatus == "FIRSTTRIAL") {
                var stageStatus = "初审";
            } else if (aData.stageStatus == "DECORATEASSESSMENT") {
                var stageStatus = "装修评估";
            } else if (aData.stageStatus == "JUDGMENT") {
                var stageStatus = "终审";
            } else if (aData.stageStatus == "JUDGMENTREPETITION") {
                var stageStatus = "高管审核";
            }

            if (aData.houseProcessStatus == "HouseFirstTrial") {
                var statusStr = "待初审";
            } else if (aData.houseProcessStatus == "HouseFirstTrialing") {
                var statusStr = "初审中";
            } else if (aData.houseProcessStatus == "HouseFirstTrialSuccess") {
                var statusStr = "初审通过";
            } else if (aData.houseProcessStatus == "HouseBack") {
                var statusStr = "初审拒绝";
                var operate = "拒绝";
            } else if (aData.houseProcessStatus == "HouseDecorateAssessment") {
                var statusStr = "待装修评估";
                var operate = "通过";
            } else if (aData.houseProcessStatus == "HouseDecorateAssessmenting") {
                var statusStr = "装修评估中";
            } else if (aData.houseProcessStatus == "HouseDecorateAssessmentSuccess") {
                var statusStr = "装修评估通过";
            } else if (aData.houseProcessStatus == "HouseJudgment") {
                var statusStr = "待终审";
                var operate = "通过";
            } else if (aData.houseProcessStatus == "HouseJudgmenting") {
                var statusStr = "终审中";
            } else if (aData.houseProcessStatus == "HouseJudgmentSuccess") {
                var statusStr = "终审通过";
                var operate = "通过";
            } else if (aData.houseProcessStatus == "HouseJudgmentBack") {
                var statusStr = "终审拒绝";
                var operate = "拒绝";
            } else if (aData.houseProcessStatus == "HouseJudgmentRepetition") {
                var statusStr = "待高管审核";
                var operate = "通过";
            } else if (aData.houseProcessStatus == "AccountSuccessful") {
                var statusStr = "高管审核通过";
                var operate = "通过";
            } else if (aData.houseProcessStatus == "HouseJudgmentRepetitionBack") {
                var statusStr = "高管审核拒绝";
                var operate = "拒绝";
            } else if (aData.houseProcessStatus == "HouseSupplement") {
                var statusStr = "补件";
                var operate = "回退补件";
            } else if (aData.houseProcessStatus == "HouseClaim") {
                var statusStr = "认领";
                var operate = "认领";
            } else if (aData.houseProcessStatus == "HOUSEASSIGN") {
                var statusStr = "指派";
            }

            $(nRow).find(".houseStatus").empty().append(statusStr);
            $(nRow).find(".operateStatus").empty().append(operate);
            $(nRow).find(".houseStatus1").empty().append(stageStatus);


        },
        "fnDrawCallback": function(oSettings) {

        },
        "fnServerParams": function(aoData) {
            $scope.queryParams.id = data.id;
            aoData.push({
                'name': 'queryParams',
                'value': $scope.queryParams,
            });
            return aoData;
        },
        "fnServerData": function(sSource, aData, fnCallback, dataTableObject) {
            //自定义给datatables传递的参数
            var obj = dataTableObject.oAjaxData,
                _baseParams = {
                    'page': obj.iDisplayStart / obj.iDisplayLength + 1,
                    'rows': obj.iDisplayLength,
                    'search': 'false',
                    'nd': '1494221804416',
                };

            var __data = angular.extend({}, _baseParams, obj.queryParams);
            rest.decoJava({
                type: "post",
                url: sSource,
                data: __data,
                beforeSend: function(request) {
                    request.setRequestHeader("token", token);
                },
                success: function(data) {
                    $scope.myDatas = data;
                    var data1 = {
                        'aaData': data.result,
                        'sEcho': obj.sEcho,
                        // 'iTotalDisplayRecords': data.result.page.recordCount,
                        'iTotalRecords': data.records,
                    };
                    fnCallback(data1);
                }
            });
        }
    };
});